/*
 * @Author: 码上talk|RC
 * @Date: 2021-08-17 14:39:47
 * @LastEditTime: 2021-09-19 14:04:59
 * @LastEditors: 码上talk|RC
 * @Description: 
 * @FilePath: /ma-portal/model/entity/revert/index.js
 * @微信:  13680065830
 * @邮箱:  3189482282@qq.com
 * @oops: Just do what I think it is right
 */
import Entity from '../../entity.class.js';
import options from '../../json/options/revert';

const _tableField = {
  sn: {
    type: 'string',
    default: ''
  },
  status: {
    type: 'int',
    default: 0
  },
  quantity: {
    type: 'int',
    default: 0
  },
  qualifiedQuantity: {
    type: 'int',
    default: 0
  },
  noQualifiedQuantity: {
    type: 'int',
    default: 0
  },
  amountPackage: {
    type: 'int',
    default: 0
  },
  createTime: {
    type: 'string',
    default: ''
  }
};

class Revert extends Entity {
  static _requestConfig = {
    app: 'portal',
    domain: 'revert'
  }

  static _form = {}

  static _options = options

  constructor (revert) {
    super(revert, { _tableField });
  }

  genSortTableData () {
    const g2sList = [];
    this._raw.revertFormSortList.forEach(i => {
      let isG2sExsit = false;
      for (let j = 0; j < g2sList.length; j++) {
        const g2s = g2sList[j];
        if (g2s.goodsItems.id === i.goodsItemsId) {
          if (i.status === 1) {
            g2s.qualified = i.quantity;
          } else {
            g2s.unqualified = i.quantity;
          }
          isG2sExsit = true;
          break;
        }
      }
      if (!isG2sExsit) {
        const g2s = {
          goodsItems: i.goodsItems,
          qualified: 0,
          unqualified: 0
        };
        if (i.status === 1) {
          g2s.qualified = i.quantity;
        } else {
          g2s.unqualified = i.quantity;
        }
        g2sList.push(g2s);
      }
    });
    return g2sList;
  }
}

export default Revert;
